<%@ Page Language="C#" MasterPageFile="~/Common/WebSiteMaster.master" AutoEventWireup="true" CodeBehind="B_JSON.aspx.cs" Inherits="ScottCateAjax2008.Lesson01.B_JSON" Title="JSON Intro" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script language="javascript" type="text/javascript">
    var xmlHttp = null;
    var response = null;
    var results = null;
        
    function InitXmlHttp() {	
	    results = document.getElementById('DisplayResults');
    	
        try {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");					
        return;
        } catch (ex) {}// catch
    	
        try {
        xmlHttp = new ActiveXObject("msxml2.xmlhttp");						
        return;
        } catch (ex) {}// catch
    	  		  		
        try {
        xmlHttp = new XMLHttpRequest();						
        return;
        } catch (ex) {}// catch
        xmlHttp = null;    	
    }// function

    function GetData(url) {
	    response = null;
	    if (!xmlHttp) InitXmlHttp();
	    
	    if (xmlHttp && url) {
	        // run sync or async? true = script will continue
	        // false = script will wait for result
	        var async = false; 
		    xmlHttp.open ( 'GET', url, async );			
		    xmlHttp.send (null);

            var data = xmlHttp.responseText;
		    var navs = eval('(' + data + ')').Nav;
		    if(navs && results) {
		        var content = new Array();
		        content[content.length] = "<ul>";
		        for(var r=0; r<navs.length; r++) {
		            content[content.length] = "<li>";
		            content[content.length] = "<a href=\"";
		            content[content.length] = navs[r].Url;
		            content[content.length] = "\">";
		            content[content.length] = navs[r].Name;
		            content[content.length] = "</a>";
		            content[content.length] = "</li>";
		            results.innerHTML = content;
		        }
		        content[content.length] = "</ul>";
                results.innerHTML = content.join('');		        
		    }//if
	    }// if
    }// function
    
    function ClearData() {
        if(results)
            results.innerHTML = '';
    }
    </script>
    
    
    
    
    
    
    
    <a href="#GetHTML" 
       onclick="GetData('B_JSONResponse.htm');">Get JSON Response</a><br />

    <a href="#ClearHTML" 
       onclick="ClearData();">Clear JSON Response</a><br /><br />

    <a href="/Utilities/ShowServerCode.aspx?res=/Lesson01/B_JSONResponse.htm">Show B_JSONResponse.htm</a>

    <div id="DisplayResults">    
    </div>

</asp:Content>










